package meterMonitor.constand;

public enum StatusCode {

    SUCCESS("0", "操作成功"), UNKNOWN("999", "系统异常");

    private String code;

    private String name;

    private StatusCode(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static StatusCode of(String code) {
        if (code == null) {
            return StatusCode.UNKNOWN;
        }
        for (StatusCode statusCode : StatusCode.values()) {
            if (statusCode.sameCodeAs(code)) {
                return statusCode;
            }
        }
        return StatusCode.UNKNOWN;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public boolean sameCodeAs(String code) {
        return this.code.equals(code);
    }

}
